package v2

import "gluenet/pkg/agent/v2/rpc"

type ClientInterface interface {
	RPCClient() rpc.Interface
	Agent(agentGuid string) ClientInterface

	ContainerGetter
	HelmGetter
	KubevirtGetter
	K8sGetter
	ProxyGetter
}

type CoreClient struct {
	rpcClient rpc.Interface
}

// create a new agent client
//
// Example:
//
//	cli, err := NewCoreClient(&rpc.Config{AgentGuid: `your agent`, NatsUrl: `nats://xx:xx`})
func NewCoreClient(cfg *rpc.Config) (*CoreClient, error) {
	rpcClient, err := rpc.NewRpcClient(cfg)
	if err != nil {
		return nil, err
	}

	return &CoreClient{
		rpcClient: rpcClient,
	}, nil
}

func (c *CoreClient) RPCClient() rpc.Interface {
	return c.rpcClient
}

func (c *CoreClient) Agent(agentGuid string) ClientInterface {
	c.rpcClient.ResetTarget(agentGuid)
	return c
}

func (c *CoreClient) Containers(guid string) ContainerInterface {
	return newContainers(c, guid)
}

func (c *CoreClient) Releases(guid string) ReleaseInterface {
	return newReleases(c, guid)
}

func (c *CoreClient) Charts(guid string) ChartInterface {
	return newCharts(c, guid)
}

func (c *CoreClient) VirtualMachines(guid string) VirtualMachineInterface {
	return newVirtualMachines(c, guid)
}

func (c *CoreClient) VirtualMachineServices(guid string) VirtualMachineServiceInterface {
	return newVirtualMachineServices(c, guid)
}

func (c *CoreClient) VirtualMachineInstances(guid string) VirtualMachineInstanceInterface {
	return newVirtualMachineInstances(c, guid)
}

func (c *CoreClient) GluenetApps(guid string) GluenetAppInterface {
	return newGluenetApps(c, guid)
}

func (c *CoreClient) Proxy() GluenetProxyInterface {
	return newGluenetProxy(c)
}

func (c *CoreClient) Maas() GluenetMaasInterface {
	return newGluenetMaas(c)
}

func (c *CoreClient) Log() GluenetLogInterface {
	return newGluenetLog(c)
}

func (c *CoreClient) Prom() GluenetPromInterface {
	return newGluenetProm(c)
}

func (c *CoreClient) Dag() GluenetDagInterface {
	return newGluenetDag(c)
}

func (c *CoreClient) Jaeger() GluenetJaegerInterface {
	return newGluenetJaeger(c)
}

func (c *CoreClient) Cprofile() GluenetCprofileInterface {
	return newGluenetCprofile(c)
}
